package com.project.ToDone;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

public class TestTestCase {

	
    //@Test
    /**
     * @Author Matthew Guzdial
     * 
     * Tests the RegexNotNull test
     * 
     */
    @Test
    public void testRegexNotNull() {
            RegexTester regex = new RegexTester();
            assertTrue(regex.stringNotNullTest("test"));
            assertTrue(regex.stringNotNullTest("tes"));
            assertTrue(regex.stringNotNullTest("te"));
            assertEquals(false, regex.stringNotNullTest(""));
            
          
            
    }
    
    /**
     * @Author Matthew Guzdial
     * 
     * Tests the regex date test
     * 
     */
    @Test
    public void testRegexDate(){
            RegexTester regex = new RegexTester();
            
            //Test that bad calls are bad
            assertFalse(regex.dateTest("99/99/99"));
            assertFalse(regex.dateTest("100/100/100"));
            assertFalse(regex.dateTest("010101"));
            assertFalse(regex.dateTest(""));
            
            //Test that good calls are good
            assertTrue(regex.dateTest("01/01/01"));
            assertTrue(regex.dateTest("12/12/12"));
    }
    
           
            /**
             * 
             * JUnit test checks the checkIfValid() method by testing if particular
             * user names are in the user list and if the method correctly identifies that
             * information.
             * 
             */
    	@Test
          public void testcheckIfValid(){
                    User u1 = new User("Elise", "elivingston@gmail.com", "elivingston3", "fishSticks");
                    User u2 = new User("Paul", "frank@gmail.com", "dicpis4", "password");
                    User u3 = new User("Tamara", "potato@gmail.com", "tamtamb55", "qwerty");
                    User u4 = new User("Jesten", "jmann@gmail.com", "ImAwesome", "hallelujah");
                    ArrayList<User> userList = new ArrayList<User>();
                    userList.add(u1);
                    userList.add(u2);
                    userList.add(u3);
                    userList.add(u4);
                    MasterControlProgram.setUsers(userList);
                    assertFalse("Username that exists is being marked as valid", MasterControlProgram.checkIfValid("elivingston3"));
                    assertTrue("Username that does not exist is being marked as invalid", MasterControlProgram.checkIfValid("IloveCats4440"));
                    ArrayList<User> emptyList = new ArrayList<User>();
                    MasterControlProgram.setUsers(emptyList);
                    assertTrue("Username that does not exist is being marked as invalid", MasterControlProgram.checkIfValid("elivingston3"));
                    emptyList.add(u1);
                    assertFalse("User name that exists is being marked as valid", MasterControlProgram.checkIfValid("elivingston3"));
                    
                    
            }
            
            
            /**
             * 
             * JUnit test for checkIfValidPassword() method. Checks to see whether or
             * not particular passwords are in the database and whether or not the method
             * is able to identify that information.
             * 
             */
    		@Test
            public void testcheckIfValidPassword(){
                    User u1 = new User("Elise", "elivingston@gmail.com", "elivingston3", "fishSticks");
                    User u2 = new User("Paul", "frank@gmail.com", "dicpis4", "password");
                    User u3 = new User("Tamara", "potato@gmail.com", "tamtamb55", "qwerty");
                    User u4 = new User("Jesten", "jmann@gmail.com", "ImAwesome", "hallelujah");
                    ArrayList<User> userList = new ArrayList<User>();
                    userList.add(u1);
                    userList.add(u2);
                    userList.add(u3);
                    userList.add(u4);
                    MasterControlProgram.setUsers(userList);
                    assertFalse("Existing password does not appear in list", MasterControlProgram.checkIfValidPassword("fishSticks"));
                    assertTrue("Passwords that do not exist are being marked as invalid", MasterControlProgram.checkIfValidPassword("salamander"));
                    ArrayList<User> emptyList = new ArrayList<User>();
                    MasterControlProgram.setUsers(emptyList);
                    assertTrue("Password that does not exist in the list is being marked as invalid", MasterControlProgram.checkIfValidPassword("fishSticks"));
                    emptyList.add(u1);
                    assertFalse("Password in list is being marked as valid.", MasterControlProgram.checkIfValidPassword("fishSticks"));
                    
                    
            }
            
            
            /**
             * Test the filter by date function by checking ALL the cases
             * 
             * @author Sean Wheeler
             * 
             */
			@Test
            public void testFilterByDate(){
                    ToDoList td = new ToDoList();
                    Event one = new Event(false, false, "04/02/12", "12:00", "", "", "Event 1", "");
                    Event two = new Event(false, false, "04/12/12", "12:00", "", "", "Event 2", "");
                    
                    ArrayList<Event> testList;
                    
                    testList = td.filterEventsByDateAfter("04/01/12");
                    
                    //Assert that no events were returned
                    assertEquals(testList.size(),0);
                    
                    td.addEvent(one);
                    
                    //Check to see that the test arraylist has not changed
                    assertEquals(testList.size(),0);
                    
                    testList = td.filterEventsByDateAfter("04/01/12");
                    
                    //Check to see if the event is returned
                    assertEquals(testList.get(0),one);
                    
                    testList = td.filterEventsByDateAfter("04/03/12");
                    
                    //Check to see if the event is not returned due to not being before the date
                    assertEquals(testList.size(),0);
                    
                    td.addEvent(two);
                    
                    //Check to see the event is not  included in the datalist
                    assertEquals(testList.size(),0);
                    
                    testList = td.filterEventsByDateAfter("04/03/12");
                    
                    //Check to see if the second event is returned
                    assertEquals(testList.get(0),two);
                    
                    testList = td.filterEventsByDateAfter("04/01/12");
                    
                    //Check to see if both events are gotten
                    assertEquals(testList.size(),2);
                    
                    testList = td.filterEventsByDateAfter("04/24/12");
                    
                    //Check to see if both events are not retrieved
                    assertEquals(testList.size(),0);
                    
                    
                    
            }
            
            
            /**
             * Test the filter by date function by checking ALL the cases
             * 
             * @author Sean Wheeler
             * 
             */
    		@Test
            public void testFilterByCompletion(){
                    ToDoList td = new ToDoList();
                    Event one = new Event(false, false, "04/02/12", "12:00", "", "", "Event 1", "");
                    Event two = new Event(false, false, "04/12/12", "12:00", "", "", "Event 2", "");
                    ArrayList<Event> testList;
                    
                    
                    testList = td.filterEventsByCompletion();
                    //Assert that no events were returned
                    assertEquals(testList.size(),0);
                    
                    
                    td.addEvent(one);
                    //Check to see that the test arraylist has not changed
                    assertEquals(testList.size(),0);
                    
                    
                    testList = td.filterEventsByCompletion();
                    //Check to see if the event is returned
                    //assertEquals(testList.get(0),one);
                    
                    
                    one.toggleCompletion();
                    testList = td.filterEventsByCompletion();
                    //Check to see if the event is not returned due to not being before the date
                    assertEquals(testList.size(),1);
                    
                    
                    td.addEvent(two);
                    //Check to see the event is not  included in the datalist
                    assertEquals(testList.size(),1);
                    
                    
                    testList = td.filterEventsByCompletion();
                    //Check to see if the first event is the only one
                    assertEquals(testList.get(0),one);
                    
                    
                    two.toggleCompletion();
                    testList = td.filterEventsByCompletion();
                    //Check to see if both events are gotten
                    assertEquals(testList.size(),2);
                    
                    one.toggleCompletion();
                    two.toggleCompletion();
                    testList = td.filterEventsByCompletion();
                    //Check to see if no events are retrieved
                    assertEquals(testList.size(),0);
                  
                    
                    
            }
            
            
            /**
             * @Author Paco Swift
             * testValidate tests the user's validate method. This test may
             * need to be fleshed out more.
             */
           @Test
                public void testValidate(){
                        User u1 = new User("Paco", "pswift3@gatech.edu", "ThePaco", "password");
                        User u2 = new User("Elise", "else.livingston@gmail.com", "Moe", "curly");
                        User u3 = new User("Harrison", "hamstereater@hotmail.com", "Papa H", "doodoo");
                        ArrayList<User> userList = new ArrayList<User>();
                        userList.add(u1);
                        userList.add(u2);
                        userList.add(u3);
                        
                        MasterControlProgram.setUsers(userList);
                        
                        assertEquals(u1.validate("ThePaco","password"),0);
                        assertEquals(u1.validate("ThePaco", "wrongpass"),1);
                        assertEquals(u1.validate("randouser","password"),2);
                        assertEquals(u1.validate("randouse","randopass"),3);
                        assertEquals(u3.validate("Papa H", "doodoo"),0);
                        assertEquals(u3.validate("HARRISONSUCKS","REALLYBAD"),3);
                        assertEquals(u2.validate("Moe", "password"),1);
                        assertEquals(u2.validate("ELISEIMO", "curly"),2);
                }
                
            
            /**
             * @author Paco Swift
             * tesFilterEventsByType checks the filterEventsByType method to make sure
             * it returns the correct list of events
             */
    		@Test
           public void testFilterEventsByType(){
                    
                    ArrayList<Event> results;
                    
                    Event goClass = new Event(true, false, "04/20/12", "12:00", "SCHOOL", "580 Turner Place NW", "Class", "Go learn stuff.");
                    Event goSleep = new Event(true, false, "05/25/12", "12:00", "PERSONAL", "580 Turner Place, NW", "Sleep", "Get some beauty sleep.");
                    Event takeTest = new Event(false, false, "04/03/12", "09:35", "SCHOOL", "580 Turner Place, NW", "Test", "Go get an A on your psych test");
                    ArrayList<Event> badList = new ArrayList<Event>();
                    badList.add(goSleep);
                    badList.add(takeTest);
                    
                    ArrayList<Event> testList = new ArrayList<Event>();
                    testList.add(goClass);
                    testList.add(goSleep);
                    testList.add(takeTest);
                    
                    ArrayList<Event> correct = new ArrayList<Event>();
                    correct.add(goClass);
                    correct.add(takeTest);
                    
                    ToDoList tdl = new ToDoList(testList);
                    results=tdl.filterEventsByType("SCHOOL");
                    assertEquals(results,correct);
                    assertNotSame(results,badList);
                    
            }

	
			/**
			 * Tests that the address test for our regex works to our specifications
			 * 
			 */
			@Test
			public void testRegexAddress(){
				RegexTester regex = new RegexTester();
				
				//Bad calls
				assertFalse(regex.addressTest("12:00"));
				assertFalse(regex.addressTest("99/99/99"));
				//Incomplete Calls
				assertFalse(regex.addressTest("1234"));
				assertFalse(regex.addressTest("1234 Main"));
				assertFalse(regex.addressTest("1234 Main St"));
				assertFalse(regex.addressTest("1234 Main St Decatur"));
				assertFalse(regex.addressTest("1234 Main St Decatur, GA"));
				//Blank test
				assertFalse(regex.addressTest(""));
				
				//Good Calls
				assertTrue(regex.addressTest("123 Main St. Decatur, GA 30033"));
				assertTrue(regex.addressTest("12 Lost Road Atlanta, GA 30332"));
				assertTrue(regex.addressTest("3015 Arbor Chase Ann Arbor, GA 42978"));
				
			}
			
			/**
			 * Tests that the username test for our RegexTester works to our specifications
			 * 
			 */
			@Test
			public void testUsername(){
				RegexTester regex = new RegexTester();
				
				//Bad calls
				//Doesn't accept names
				assertFalse(regex.usernameTest("John Smith"));
				//Doesn't accept crazed symbols
				assertFalse(regex.usernameTest("!@#$%^&*"));
				assertFalse(regex.usernameTest("  "));
				//Blank
				assertFalse(regex.usernameTest(""));
				
				
				//Good calls
				assertTrue(regex.usernameTest("mguzdial3"));
				assertTrue(regex.usernameTest("username"));
				assertTrue(regex.usernameTest("password"));
				assertTrue(regex.usernameTest("0101101"));
			}
}
